package com.cstor.liang.config;

import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.HttpPutFormContentFilter;

import javax.servlet.*;
import java.util.EnumSet;

/**
 * Created by Administrator on 2017/10/17.
 */
@Configuration
public class GoServletContextInitializer implements ServletContextInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {

        //HttpPutFormContentFilter 解决 Put 请求的表单参数传递
        FilterRegistration.Dynamic httpPutFormContentFilter =
                servletContext.addFilter("httpPutFormContentFilter", HttpPutFormContentFilter.class);
        httpPutFormContentFilter.addMappingForUrlPatterns(
                EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE),
                false, "/*");

        //statViewServlet
        StatViewServlet statViewServlet = new StatViewServlet();
        ServletRegistration.Dynamic dynamic = servletContext.addServlet(
                "statViewServlet", statViewServlet);
        dynamic.setLoadOnStartup(2);
        dynamic.addMapping("/druid/*");
    }
}
